package com.itheima.info.manage.sysytem.service;

import com.itheima.info.manage.sysytem.dao.StudentDao;
import com.itheima.info.manage.sysytem.domain.Student;

public class StudentService {
    //创建StudentDao对象
   private StudentDao StudentDao=new StudentDao();

    public boolean addStudent(Student stu) {
        //将学生对象，传递给StudentDao库管中的addStudent方法
        //将返回的boolean类型的结果，返还给StudentController
        return StudentDao.addStudent(stu);
    }



    public boolean isExists(String sid) {
        Student []stus=StudentDao.findallStudent();
        boolean flag=false;
        for (int i = 0; i <stus.length ; i++) {
            Student stu=stus[i];
            if (stu!=null&&stu.getSid().equals(sid)){
                flag=true;
            }
        }
        return flag;
    }

    public Student[] findallStudent() {
        Student[]stus=StudentDao.findallStudent();
        boolean flag=false;
        for (int i = 0; i <stus.length ; i++) {
            Student stu=stus[i];
            if (stu != null) {
                flag=true;
            }
        }
        if (flag){
            return  stus;
        }else{
            return null;
        }
    }

    public   void deleteStudent(String sid) {
        StudentDao.deleteStudent(sid);
    }

    public void updateStudent(String sid, Student newstu) {
        StudentDao.updateStuent(sid,newstu);
    }
}
